package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.Orders;
import com.fantastic.service.zjs.OrdersService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/5 20:28
 * @description: 订单信息表请求控制器
 */
@RestController
@RequestMapping("/orders")
public class OrdersControllerAdmin {
    @Resource
    private OrdersService ordersService;

    /**
     * 查询订单信息
     *
     * @param orders
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listOrders")
    public ResultData listOrders(Orders orders, @RequestParam(name = "page",
            defaultValue = "1") int pageNum,
                                 @RequestParam(name = "limit", defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Orders> list = ordersService.listOrders(orders);
        PageInfo<Orders> PageInfo = new PageInfo<>(list);
        return new ResultData(RespStatusInfo.OK, PageInfo);
    }

    /**
     * 查询单个订单信息
     *
     * @param orderId
     * @return
     */
    @GetMapping("/getOrders")
    public ResultData getOrders(String orderId) {
        return new ResultData(RespStatusInfo.OK, ordersService.getOrders(orderId));
    }

    /**
     * 添加订单信息
     *
     * @param orders
     * @return
     */
    @PostMapping("/insertOrders")
    public ResultData insertOrders(Orders orders,Integer couponsId) {
        return new ResultData(RespStatusInfo.OK, ordersService.insertOrders(orders,couponsId));
    }

    /**
     * 修改订单信息
     *
     * @param orders
     * @return
     */
    @PostMapping("/updateOrders")
    public ResultData updateOrders(Orders orders) {
        return new ResultData(RespStatusInfo.OK, ordersService.updateOrders(orders));
    }


    /**
     * 删除订单信息
     *
     * @param orderId
     * @return
     */
    @PostMapping("/deleteOrders")
    public ResultData deleteOrders(Integer orderId) {
        return new ResultData(RespStatusInfo.OK, ordersService.deleteOrders(orderId));
    }
}
